<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>菜单管理</title>
    <%@include file="../../public/commonCss.jsp" %>
    <%@include file="../../public/commonJs.jsp" %>
</head>
<body ms-controller="main">
<div id="wrapper">
    <div class="boxmain whiteBox lrbox">
        <div class="lrboxmain borderL" style="margin-left:0%">
            <div class="from-header borderB contentbox">
                <div>
                    <span class="font14"> 所属分类:</span><a id="category"><span class=" fontOrange2">菜单管理</span></a>
                    <button class="layui-btn layui-btn-normal layui-btn-small fr" style="margin-right:15px" ms-click="showAddLayer()">
                        新增菜单
                    </button>
                </div>
            </div>
            <div class="from-body withheader contentbox" style=" overflow: auto;">
                <table class="layui-table">
                    <thead>
                    <tr align="center">
                        <th>行号</th>
                        <th>菜单名称</th>
                        <th>URL</th>
                        <th>LOGO</th>
                        <th>上级菜单</th>
                        <th>排序</th>
                        <th>菜单分类</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr align="center" ms-repeat="tableDatas">
                        <td>{{$index+1}}</td>
                        <td align="right" ms-if="el.parentName!=null">{{el.name}}</td>
                        <td ms-if="el.parentName==null">{{el.name}}</td>
                        <td>{{el.url}}</td>
                        <td>{{el.logoUrl}}</td>
                        <td>{{el.parentName}}</td>
                        <td>{{el.sortOrder}}</td>
                        <td>{{el.type=="0"?"目录":"功能"}}</td>
                        <td>
                            <button class="layui-btn layui-btn-small" style="margin-right:15px" ms-click="showEditLayer(el)">
                                修改
                            </button>
                            <button class="layui-btn layui-btn-danger layui-btn-small" ms-click="deleteData(el)">删除</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- whitebox -->
</div>
<script type="text/javascript">
    var vm;
    avalon.ready(function () {
        vm = avalon.define({
            $id: "main",
            tableDatas: [],//图片数据
        })
        avalon.scan();
        loadTableData();
    });
    //弹出添加菜单对话框
    function showAddLayer() {
        layer.open({
            type: 2,
            title: '新增菜单',
            area: ['520px', '460px'],
            fix: false, //不固定
            maxmin: false,
            content: '${ctx}/menuController/toMenuForm.action'
        });
    }
    //弹出添加菜单对话框
    function showEditLayer(el) {
        layer.open({
            type: 2,
            title: '编辑菜单',
            area: ['520px', '460px'],
            fix: false, //不固定
            maxmin: false,
            content: '${ctx}/menuController/toMenuForm.action?id=' + el.id
        });
    }

    function loadTableData() {
        ajaxUtil.post('${ctx}/menuController/selectAllMenus.action', "", true, function (data) {
            vm.tableDatas = data.data;
        });
    }
    //删除
    function deleteData(el) {
        layui.layer.confirm("确认删除吗？", {
            title: '提醒',
            btn: ['确定', '取消'] //按钮
        }, function (r) {
            var dataStr = {id: el.id};
            $.ajax({
                type: 'post',
                url: '${ctx}/menuController/deleteMenu.action',
                data: dataStr,
                dataType: "json",
                timeout: 10000,
                success: function (data) {
                    closeDialog();
                    if (data.code == 0) {
                        layui.layer.msg('删除成功.', {icon: 1});
                        loadTableData();
                    } else {
                        layui.layer.msg('删除失败.', {icon: 2});
                    }
                }
            });

        });

    }
</script>
</body>
</html>